#activity sorted by s[]
def greedy_activity_selector(s,f):
    n=len(s)
    A=[n]
    i=n-1
    for m in xrange(n-2,0,-1):
        if f[m]<=s[i]:
            A.append(m+1)
            i=m
    return A

if __name__=='__main__':
    s=[0,1,2,3,3,5,5,6,8,8,12]
    f=[6,4,13,5,8,7,9,10,12,11,14]
    print 's:', s
    print 'f:', f
    A=greedy_activity_selector(s,f)
    print 'ans:'
    for i in A[::-1]:
        print '[',s[i-1],f[i-1],']'
